#include <stdio.h>
#include <stdarg.h>
    
struct person{
    char* name;
    int age;
    char score;
}__attribute__((packed));

/* 用__attribute__((packed))来指定当前struct不进行字节对齐 */
/* packed可以指定为4或8等其他位数 */

int push_out(const char* format,...)
{   
    /* char* p = (char*)&format; */
    va_list p;
    int i;
    struct person per;
    char* c;
    double d;
    
    printf("arg1 %s\n", format);
    /* p = p + sizeof(char*); */
    /* i = *((int *)p); */
    va_start(p,format);

    i=va_arg(p,int);

    printf("arg2 %d\n", i);

    /* p = p+sizeof(int); */
    /* per = *((struct person *)p); */
    per=va_arg(p,struct person);
    printf("arg3 name = %s age = %d score = %c \n",per.name,per.age,per.score);

    /* printf("&name = %p name = %s \n", &name,name); */
    
    /* p = p+sizeof(struct person); */
    /* char* str = *((char**)p); */
    /* c=va_arg(p,char); */
    c=va_arg(p,int);
    printf("arg4 c = %c \n",c);

    d = va_arg(p,double);
    printf("arg5 d=%f\n", d);

    /* p = (char*)0;//避免野指针出现 */

    va_end(p);

    return 0;
}

int main(int argc, char *argv[])
{
    printf("sizeof char %d \n", sizeof(char));
    printf("sizeof int %d \n", sizeof(int));
    printf("sizeof char * %d \n", sizeof(char*));
    printf("sizeof char ** %d \n", sizeof(char **));

    struct person per = {"rain",26,'S'};
    printf("struct person sizeof = %d\n",sizeof(per));
    printf("struct person &name  %p\n",&per.name);
    printf("struct person &age   %p\n",&per.age);
    printf("struct person &score %p\n",&per.score);

    push_out("hello",7,per,'f',3.14159); 

    return 0;
}
